package com.sc.byahi.user.client;

import com.google.gwt.ajaxloader.client.AjaxLoader;
import com.google.gwt.ajaxloader.client.AjaxLoader.AjaxLoaderOptions;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.History;
import com.sc.byahi.user.client.components.HistoryTokens;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class _Byahi implements EntryPoint {

	public void onModuleLoad() {
		// From http://code.google.com/apis/maps/signup.html
		/*
		String mapKey = "";
		if (Util.appEngine) {
			// https://byahi-m-ms-t.appspot.com
			// mapKey = "ABQIAAAAwaAh1xUEdsIzfVcvT_HIsxQTg-CKdXKCzbCewuMGvJLGl8yVThTLJlXpRWvE_RyXXOFDwhEvJTIGug";
			// TODO: it is not working with http://byahi.com or any such value as it is redirected
			// Also in IFrame approach, histroy tokens are not visible in browser
			// http://byahi.com so that it will work for matri as well as home
			mapKey = "ABQIAAAAwaAh1xUEdsIzfVcvT_HIsxQMOJON1fHhUzth8sk379BlXlBEVhRL7OlDOk7WKxoAqrWUCSyBeqG34g";
			// www.byahi.com
			// mapKey = "ABQIAAAARt4xIclWU-f-xwlS0E3rxRQpk22qhQ2UAZ9x98ZfVsj9XQHdThTen3RqP5rrzZjrRocKFBVunYKP6A";
		} else {
			mapKey = "ABQIAAAAqBgIuQ5ro5kLoFDLBBEyChSBmOYutqn76vEVjX0OUOio3DvGphT2hs1aL3YdZYtcipguQXBCqPHieA";
		}
		 */
		// buildUi();
		AppController appController = AppController.get();// so that app controller constructor is fired

		// If the application starts with no history token, redirect to a new 'dashboard' state.
		String initToken = History.getToken();
		if (initToken.length() == 0) {
			History.newItem(HistoryTokens.DASHBOARD, false);
		}

		// Every time a link is pasted then user data must be refreshed
		appController.refreshInitData(true);
		
		// Only one time initialization
		appController.refreshLists();
		
		AjaxLoaderOptions options = AjaxLoaderOptions.newInstance();
		options.setOtherParms("sensor=false&libraries=places&language=en");
		Runnable callback = new Runnable() {
			public void run() {
				// UIUtil.showDialog(Arrays.asList("AJAX Library loaded Google Maps."), "Map loading success.");
			}
		};
		AjaxLoader.loadApi("maps", "3", callback, options);
	}
}
